package com.test1231;

import com.java1228.M;

public class Test01 {
    public static void main(String[] args) {
        // (1)根据需求设计编写相关的类和方法
        // 提示：用数组存储员工

        // 公司
        CompanyA c = new CompanyA("阿里");

        // 添加合同工：固定工资
        c.add(new MemberA("张三",3000));
        c.add(new MemberA("张三",3000));

        // 添加计时工：工时、工时费
        c.add(new MemberB("张三",50,100));
        c.add(new MemberB("张三",60,100));

        // 求所有员工总工资
        double salary = c.getAllSalary();
        System.out.println(salary);
    }

}
class CompanyA{
    private String name;
    private Member[] emp = new Member[4];
    private int index =0;

    public CompanyA() {
    }

    public CompanyA(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    public void add(Member m){
        emp[index++]=m;
    }//面向父类做开发
    public double getAllSalary(){
        int sum =0;
        for(int i=0;i<emp.length;i++){
            if(emp[i] instanceof MemberA){//也可以每类员工设计一个返回工资的方法 sum+=emp[i].m1();
                MemberA a= (MemberA)emp[i];
                sum+=a.getWage();
            }else {
                MemberB b = (MemberB)emp[i];
                sum+=b.getHours()*b.getHours_wage();
            }
        }
        return sum;
    }
}
abstract class Member{
    private String name;
    private CompanyA com;

    public Member() {

    }

    public Member(String name, CompanyA com) {
        this.name = name;
        this.com = com;
    }

    public Member(String name) {
        this.name = name;

    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public CompanyA getCom() {
        return com;
    }

    public void setCom(CompanyA com) {
        this.com = com;
    }

    @Override
    public String toString() {
        return
                "员工名:" + name ;

    }
}